package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4FlatMap {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("flatMap")
    val sc = new SparkContext(conf)

    //读取文件
    val linesRDD: RDD[String] = sc.textFile("data/words.txt")

    /**
     * flatMap:一行转换成多行，相当于sql中的explode
     */
    val wordsRDD: RDD[String] = linesRDD.flatMap(line => line.split(","))

    wordsRDD.foreach(println)
  }
}
